//
//  BigScrollView.m
//  UI_06作业滚动视图
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BigScrollView.h"
#import "SmallScrollView.h"
@interface BigScrollView()
@property (nonatomic,retain)SmallScrollView *smallScrollView;
@property (nonatomic,retain)UIPageControl *pageControl;
@end
@implementation BigScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       self.imageArray = [NSArray array];
        [self createScrollView];
    }
    return self;
}
- (void)createScrollView{
    self.smallScrollView = [[SmallScrollView alloc] initWithFrame:self.frame];
//    self.smallScrollView.delegate = self;
    self.smallScrollView.backgroundColor = [UIColor redColor];
    [self addSubview:_smallScrollView];
    
    //创建pageControl
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) / 5 * 3.5, CGRectGetWidth(self.bounds), CGRectGetWidth(self.bounds) / 5 * 2)];
    [self addSubview:_pageControl];
    
    [self.pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];
    
}
- (void)setImageArray:(NSArray *)imageArray{
    if (_imageArray != imageArray) {
        [_imageArray release];
        _imageArray = [imageArray retain];
        self.pageControl.numberOfPages = self.imageArray.count;
        [self.smallScrollView addPicture:self.imageArray];
    }
}
- (void)pageControlAction:(UIPageControl *)page{
    self.smallScrollView.contentOffset = CGPointMake(page.currentPage * CGRectGetWidth(self.bounds), 0);
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    self.pageControl.currentPage = scrollView.contentOffset.x / CGRectGetWidth(self.bounds);
}
@end
